package com.qf.service.impl;

import com.qf.po.Userinfo;
import com.qf.repository.UserinfoRepository;
import com.qf.service.UserinfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class UserinfoServiceImpl implements UserinfoService {
    @Autowired
    UserinfoRepository userinfoRepository;
    @Override
    public Userinfo find(String username) {
        Userinfo byUsername = userinfoRepository.findByUsername(username);
        return byUsername;
    }

    @Override
    public Userinfo adduserinfo(Userinfo userinfo) {
        Userinfo save = userinfoRepository.save(userinfo);
        return save;
    }

    @Override
    public boolean deluserinfo(Integer id) {
        try {
            userinfoRepository.deleteById(id);
            return true;
        }catch (Exception e){
            return false;
        }
    }

    @Override
    public Userinfo updateuserinfo(Userinfo userinfo) {
        Userinfo userinfo1 = userinfoRepository.saveAndFlush(userinfo);
        return userinfo1;
    }
}
